package org.films.domain;

import javax.persistence.Entity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.roo.addon.entity.RooEntity;
import javax.validation.constraints.NotNull;
import org.films.domain.Category;

import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import javax.persistence.UniqueConstraint;

import java.util.Set;
import org.films.domain.Film;
import java.util.HashSet;
import javax.persistence.ManyToMany;
import javax.persistence.CascadeType;

@Entity
@RooJavaBean
@RooToString
@RooEntity(finders = { "findCategorysByNameEquals" })
public class Category {

    @NotNull
    private String name;

    @ManyToOne(targetEntity = Category.class)
    @JoinColumn
    private Category parent;

    @ManyToMany(cascade = CascadeType.REMOVE)
    @JoinTable(name = "CATEGORY_FILM", joinColumns = { @JoinColumn(name = "CATEGORY_ID") }, inverseJoinColumns = @JoinColumn(name = "FILM_ID"), uniqueConstraints = { @UniqueConstraint(columnNames = {
			"FILM_ID", "CATEGORY_ID" }) })
    private Set<Film> films = new HashSet<Film>();
}
